package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
   public void work(BookList bookList){
        System.out.println("增加图书");
       System.out.println("请输入书名");
       Scanner sc = new Scanner(System.in);
       String name = sc.nextLine();
       System.out.println("请输入作者");
       String author = sc.nextLine();
       System.out.println("请输入类型");
       String type = sc.nextLine();
       System.out.println("请输入价格");
       int price = sc.nextInt();
       Book book = new Book(name,author,price,type);
       int currentSize = bookList.getUsedSize();
       for(int i = 0;i < currentSize;i++) {
          Book tmp = bookList.getBook(i);
          if(tmp.getName().equals(name)) {
              System.out.println("已经存在这本书了，不能再放入了");
              return ;
          }
       }
       bookList.setBook(book);
       bookList.setUsedSize(currentSize+1);
    }
}
